const router = require('koa-router')()
const User = require('../model/user')

router.prefix('/users')

router.get('/', async (ctx, next) => {
  if (ctx.token) {
    let data = await User.findById(ctx.token.id);
    if (data) {
      console.log(data);
      data.profile = data.profile || '爱我所爱，一生无悔'
      await ctx.render('user/index', data)
    } else {
      ctx.body = '无效的用户'
    }
  } else {
    ctx.body = '无效的token'
  }
})

module.exports = router
